// import { resolve } from "core-js/es6/promise";
// import { reject } from "core-js/fn/promise";

import store from '@/store'
import {Toast} from 'vant'
export default function () {
    return new Promise((resolve, reject) => {

        // 刷新页面 信息保存  重新登录
        let token = localStorage.getItem('token');
        let tokenExpired = localStorage.getItem('tokenExpired');   // 时间戳


        if (token) {
            // 原来登陆过
            let now = new Date().getTime()
            if (now >= Number(tokenExpired)) {
                // token过期时
                localStorage.removeItem('token')
                localStorage.removeItem('tokenExpired')
                Toast("身份验证已过期，请重新登录");
                // return;

                resolve()

            } else {
                Toast.loading({
                    message: '加载中...',
                    forbidClick: true,
                });


                // 请求接口
                store.dispatch("getuserInfo", token).then(res => {
                    // app.$mount('#app')
                    resolve()
                    Toast.clear()
                }).catch(err=>{
                Toast("网络异常，请查看网络是否连接");
                reject()
                })
            }
        } else {
            // 未登陆过
            // app.$mount('#app')
            resolve()
        }

    })
}